package demo4.service;

import demo4.dao.IUserDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class UserService implements IUserService {
    @Autowired
    private IUserDAO userDAO;
    @Override
    public boolean login(String username, String password) {
        System.out.println("UserService:根据用户名查询该用户信息");
        boolean userinfo = userDAO.findUserByName(username);
        if (userinfo){
            System.out.println("UserService:比对密码是否正确");
            if (Math.random()<0.5){
                System.out.println("UserService:密码正确，登陆成功");
                return true;
            }else{
                System.out.println("UserService:密码错误，登陆失败");
                return false;
            }
        }else {
            System.out.println("UserService:用户名不存在，登陆失败");
            return false;
        }
    }

}
